package com.dcivision.alert.core;

import java.sql.Connection;
import java.sql.Timestamp;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.SessionContainer;

public class AdapterMaster {

  public static final String REVISION = "$Revision: 1.9 $";


    private SessionContainer sessionContainer;
    private Connection conn;

    public AdapterMaster(SessionContainer sessionContainer, Connection conn) {
        this.sessionContainer = sessionContainer;
        this.conn = conn;
    }

    public void release() {
      this.sessionContainer = null;
      this.conn = null;
    }

    public void call(String objectType, Integer objectID, String eventType, String objectName, Timestamp refDate, String eventName, Integer creatorID) throws ApplicationException {
      StandardAdapter[] adapters = this.getAdapters();
      for (int i = 0; i < adapters.length; i++) {
        adapters[0].setNecessaryResource(sessionContainer, conn);
        adapters[0].call(objectType, objectID, eventType, objectName, refDate, eventName, creatorID);
      }
    }

    public void call(String objectType, Integer objectID, String eventType,
                     String objectName, Timestamp refDate, String eventName, Integer creatorID, Integer targetDocID) throws ApplicationException {
      StandardAdapter[] adapters = this.getAdapters();
      for (int i = 0; i < adapters.length; i++) {
        adapters[0].setNecessaryResource(sessionContainer, conn);
        adapters[0].call(objectType, objectID, eventType, objectName, refDate, eventName, creatorID, targetDocID);
      }
    }

    public StandardAdapter[] getAdapters() {
        StandardAdapter[] sas = new StandardAdapter[1];
        sas[0] = new NotificationAdapter(sessionContainer,conn);
        return sas;
    }
}
